

var a = getApp(),
  change = null;
var progressnum=0;
Page({
  data: {
    searchClass: "",
    pro:0,
    showprogress:false,
    slides: [],//轮播图
    department: [{
      tag: "皮肤科",
      icon: "pifuke color1"
    }, {
      tag: "推拿",
      icon: "tuina color2"
    }, {
      tag: "骨科",
      icon: "guke color3"
    }, {
      tag: "耳鼻咽喉",
      icon: "erbihouke color4"
    }, {
      tag: "检验",
      icon: "jianyan color5"
    }, {
      tag: "B超",
      icon: "Bchaoyuyue-K color6"
    }, {
      tag: "科室7",
      icon: "wrong color7"
    }, {
      tag: "科室8",
      icon: "wrong color8"
    }],
    searchDoctor: [],
    images:[
      { url:"../../../images/docker/lbt1.png"},
      { url: "../../../images/yysc4.jpg" },
      { url: "../../../images/yysc3.jpg" },
      { url: "../../../images/yysc5.jpg" },
      { url: "../../../images/yysc6.jpg" },

    ]
  },
  onLoad(options) {
    var that=this;
    //进度条
    var timepro=setInterval(function(){
      progressnum++;
      that.setData({
        pro:progressnum
      })
      if(that.data.pro>100){
        that.setData({
          showprogress: true
        })
      }
    },20)
    wx.showToast({
      title: '加载中...',
      icon:"loading",
      duration:1000,
      success:function(){
        let token = wx.getStorageSync('usermsg');
        console.log(token)
        if (!token) {
          wx.showModal({
            title: '还未登录！',
            content: '请先登录在访问...',
            success(res) {
              if (res.confirm) {
                wx.navigateTo({
                  url: '../../loginandregister/loginindex/loginindex',
                })
              } else if (res.cancel) {

              }
            }
          })
        }
      }
    })
    
    const slides = [
      { image: 'class="background" mode="widthFix" src="../../images/home_home.png', link: '' },
      { image: 'http://ww1.sinaimg.cn/mw690/006ThXL5ly1fj6ckx9tlwj30u00fqk8n.jpg', link: '/pages/list/list?cat=10' }
    ]
  },
  hiddprogress:function(){
    var that = this;
    console.log("加载完成")
    that.setData({
      showprogress: true
    })
  },

  mydiaglist: function () {
    setTimeout(function () {
      wx.hideLoading()
    }, 2000)

    wx.navigateTo({
      url: '../facevisit/facevisit',
    })
  },
  /**
   * 搜索栏聚焦
   */
  searchFocus: function () {
    this.setData({
      searchClass: "inputFocus"
    });
  },
  /**
   * 搜索栏失焦
   */
  searchBlur: function () {
    this.setData({
      searchClass: ""
    })
  },
  /**
   * 搜索关键词
   */
  searchKey: function (e) {

    // 节流算法
    change && clearTimeout(change);

    change = setTimeout(() => {
      change = null;
      let val = e.detail.value;
      val && a.request({
        "doc_name": val,
        "depId": -1,
        "subdepId": -1
      }, "searchDoctor", data => {
        data = data.data;
        if (typeof data == "object") {
          data.map && data.map(res => {
            res.split = res.name.split(val);
            res.key = val;
            return res;
          });
          this.setData({
            searchDoctor: data
          });
        }
      });
    }, 500);
  },
  newpatient:function(){
    wx.navigateTo({
      url: '../newpatientsmsg/newpatientsmsg',
    })
  },
  lookpatiesmsg:function(){
    wx.navigateTo({
      url: '../patientinformation/patientinformation',
    })
  },
  newmyintroduction:function(){
    wx.navigateTo({
      url: '../newinrtoductionpage/newinrtoductionpage',
    })
  }
});